package com.feishi.core.analytic.element;

import com.feishi.core.analytic.PoType;
import com.feishi.core.analytic.packing.encode.EncodeExecutor;
import com.feishi.core.analytic.packing.encode.EncodeParam;
import com.feishi.core.analytic.parser.PoParser;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by caixq on 5/12 012.
 */
public class AnalyticStaticContentEncodeDataElement<T> extends AnalyticStaticInputDataElement<T>{

    public Map<Object,EncodeExecutor> encodeExecutor=new HashMap<>();


    public AnalyticStaticContentEncodeDataElement(int length) {
        super(length);
        initType();
    }

    private void initType() {
        this.type= PoType.ELEMENT_CONTENT_ENCODE;
    }

    public AnalyticStaticContentEncodeDataElement(String name, int length) {
        super(name, length);
        initType();
    }
    public AnalyticStaticContentEncodeDataElement(String name, int length, PoParser<T> parser) {
        super(name, length, parser);
        initType();
    }
    public byte[] encode(byte[] content, byte[] encodeType, EncodeParam param){
        if(encodeType==null||param==null||encodeExecutor.get(getValue(encodeType))==null){
            return content;
        }
        return encodeExecutor.get(getValue(encodeType)).encode(content,param);
    };
    public byte[] decode(byte[] content, byte[] encodeType, EncodeParam param){
        if(encodeType==null||param==null||encodeExecutor.get(getValue(encodeType))==null){
            return content;
        }
        return encodeExecutor.get(getValue(encodeType)).decode(content,param);
    };


}
